using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rtl.SharePoint.WebControls;


namespace Rtl.SharePoint
{
    public class USAddressField : SPFieldMultiColumn
    {

        #region Globals: Constants and Variables

        internal const string PROP_NAME_CTY = "DefaultCity";
        internal const string PROP_NAME_ST = "DefaultState";

        #endregion

        #region USAddressField: Constructors

        public USAddressField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
            // do nothing
        }

        public USAddressField(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        {
            // do nothing
        }

        #endregion

        #region SPField: Common Overrides

        public override BaseFieldControl FieldRenderingControl
        {
            get
            {
                BaseFieldControl fieldControl = new USAddressFieldControl();
                fieldControl.FieldName = InternalName;
                return fieldControl;
            }
        }

        // Returns the field value object
        public override object GetFieldValue(string value)
        {
            // Using the helper class USAddressFieldValue,
            // return an object that represents the ";#" delimited
            // string of values that makeup the US Address data
            // as public properties
            // Example value: ;#123 Main St.;#;#Osseo;#MN;#55369;#
            if (!string.IsNullOrEmpty(value))
            {
                return new USAddressFieldValue(value);
            }
            else
            {
                return null;
            }
        }

        #endregion

        #region USAddressField: Configuration Properties

        public string DefaultCity
        {
            get { return this.GetCustomProperty(PROP_NAME_CTY).ToString(); }
            set { this.SetCustomProperty(PROP_NAME_CTY, value); }
        }

        public string DefaultState
        {
            get { return this.GetCustomProperty(PROP_NAME_ST).ToString(); }
            set { this.SetCustomProperty(PROP_NAME_ST, value); }
        }

        #endregion
    }
}
